/* The following function creates an XMLHttpRequest object... */

function createRequestObject(){
	var request_o; //declare the variable to hold the object.
	var browser = navigator.appName; //find the browser name
	if(browser == "Microsoft Internet Explorer"){
		/* Create the object using MSIE's method */
		request_o = new ActiveXObject("Microsoft.XMLHTTP");
	}else{
		/* Create the object using other browser's method */
		request_o = new XMLHttpRequest();
	}
	return request_o; //return the object
}

/* You can get more specific with version information by using
parseInt(navigator.appVersion)
Which will extract an integer value containing the version
of the browser being used.
*/
/* The variable http will hold our new XMLHttpRequest object. */
var http = createRequestObject();


function setLink(link){
	/* Create the request. The first argument to the open function is the method (POST/GET),
	and the second argument is the url...
	document contains references to all items on the page
	We can reference document.form_category_select.select_category_select and we will
	be referencing the dropdown list. The selectedIndex property will give us the
	index of the selected item.
	*/

	window.location.href=link;
}





/* Function called to get the product categories list */
function getLink(acao, cod){
	/* Create the request. The first argument to the open function is the method (POST/GET),
	and the second argument is the url...
	document contains references to all items on the page
	We can reference document.form_category_select.select_category_select and we will
	be referencing the dropdown list. The selectedIndex property will give us the
	index of the selected item.
	*/

	var cod;
	var acao;

	if(!cod){var cod ='';}
	http.open('get', 'carrega_include.jsp?noverifica=1&'+ acao +'='+ cod);


	/* Define a function to call once a response has been received. This will be our
	handleProductCategories function that we define below. */
	http.onreadystatechange = DivInclude;
	/* Send the data. We use something other than null when we are sending using the POST
	method. */
	http.send(null);
}




function setConteudo(qdiv, conteudo){
	var qdiv;
	var conteudo;

	http.open('get', 'config.php');
	http.onreadystatechange = QualDiv;
	http.send(null);


	function QualDiv(){
		if(http.readyState == 1){
			var response = "<img src=images/loading2.gif>";
			document.getElementById(qdiv).innerHTML = response;
		}
		if(http.readyState == 4){
			var response = conteudo;
			document.getElementById(qdiv).innerHTML = response;
		}
	}
}

function getSelect(qdiv, cod, tabela){
	var qdiv;
	var cod;
	var tabela;

	//alert('funcoes/getselect.jsp?tabela='+ tabela +'&cod='+ cod);
	http.open('get', 'funcoes/externo_getselect.jsp?tabela='+ tabela +'&cod='+ cod);
	http.onreadystatechange = QualDiv;
	http.send(null);

	function QualDiv(){
		if(http.readyState == 1){
			var response = "<img src=images/loading2.gif>";
			document.getElementById(qdiv).innerHTML = response;
		}
		if(http.readyState == 4){
			var response = http.responseText;
			document.getElementById(qdiv).innerHTML = response;
		}
	}
}

/* Function called to handle the list that was returned from the internal_request.jsp file.. */
function DivInclude(){
	/* Make sure that the transaction has finished. The XMLHttpRequest object
	has a property called readyState with several states:
	0: Uninitialized
	1: Loading
	2: Loaded
	3: Interactive
	4: Finished */

	if(http.readyState == 1){
		var response = "<div class='loading'><br>Carregando...<br><img src=images/loading.gif><br clear=all /></div>";
		document.getElementById('loading').innerHTML = response;
	}
	if(http.readyState == 4){ //Finished loading the response
		/* We have got the response from the server-side script,
		let's see just what it was. using the responseText property of
		the XMLHttpRequest object. */
		var response = http.responseText;
		/* And now we want to change the product_categories <div> content.
		we do this using an ability to get/change the content of a page element
		that we can find: innerHTML. */
		document.getElementById('include').innerHTML = response;
		document.getElementById('loading').innerHTML = '';
	}
}

function getLivros(qdiv, param1, param2, param3, param4){
	var qdiv;
	var param1;
	var param2;
	var param3;
	var param4;

	http.open('get', 'rels/bibl_melhores_leitores_livros.jsp?param1='+ param1 +'&param2='+ param2 +'&param3='+ param3 +'&param4='+ param4);
	http.onreadystatechange = QualDiv;
	http.send(null);

	function QualDiv(){
		if(http.readyState == 1){
			var response = "<img src=images/loading2.gif>";
			document.getElementById(qdiv).innerHTML = response;
		}
		if(http.readyState == 4){
			var response = http.responseText;
			document.getElementById(qdiv).innerHTML = response;
		}
	}
}

function getConteudo(qdiv, qfile, param1, param2){
	var qdiv;
	var qfile;
	var param1;
	var param2;

	http.open('get',  qfile +'.jsp?param1='+ param1 +'&param2='+ param2);
	// alert(qfile +'.jsp?param1='+ param1 +'&param2='+ param2);
	// exit;
	http.onreadystatechange = QualDiv;
	http.send(null);

	function QualDiv(){
		if(http.readyState == 1){
			var response = "<img src=images/loading2.gif>";
			document.getElementById(qdiv).innerHTML = response;
		}
		if(http.readyState == 4){
			var response = http.responseText;
			document.getElementById(qdiv).innerHTML = response;
		}
	}
}

function getconteudo2(qdiv, qfile, param1, param2){
	var qdiv;
	var qfile;
	var param1;
	var param2;

	http.open('get',  qfile +'.jsp?param1='+ param1 +'&param2='+ param2);
//	 alert(qfile +'.jsp?param1='+ param1 +'&param2='+ param2);
//	 exit;
	http.onreadystatechange = QualDiv;
	http.send(null);

	function QualDiv(){
		if(http.readyState == 1){
			var response = "<img src=images/loading2.gif>";
			document.getElementById(qdiv).innerHTML = response;
		}
		if(http.readyState == 4){
			var response = http.responseText;
			document.getElementById(qdiv).innerHTML = response;
		}
	}
}